
<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.paths.core }}css/login.css?v={{ layui.admin.v }}" media="all">


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>{{ lang1['create account'] }}</h2>
      <p> </p>
    </div>
    <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-email" for="LAY-user-login-cellphone"></label>
        <input type="text" name="email" id="LAY-user-login-cellphone" lay-verify="email" placeholder="{{ lang1['email'] }}" class="layui-input">
      </div>
      <div class="layui-form-item">
        <div class="layui-row">
          <div class="layui-col-xs7">
            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="{{ lang1['captcha'] }}" autocomplete="off" class="layui-input">
          </div>
          <div class="layui-col-xs5">
            <div style="margin-left: 10px;">
              <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-reg-getsmscode">{{ lang1['get captcha'] }}</button>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="{{ lang1['password'] }}" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
        <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="{{ lang1['confirm password'] }}" class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
        <input type="text" name="nickname" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="{{ lang1['nickname'] }}" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-share" for="LAY-user-login-parentid"></label>
        <input type="text" name="parentid" value="{{ }}" id="LAY-user-login-parentid" lay-verify="parentid" placeholder="{{ lang1['parentid'] }}" class="layui-input" >
      </div>

      <div class="layui-form-item">
        <input type="checkbox" name="agree" lay-skin="primary" title="{{ lang1['agreement and privacy policy'] }}" checked>
      </div>

      <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">{{ lang1['sign up'] }}</button>
      </div>
      <div class="layui-trans layui-form-item layadmin-user-login-other">

        
        <a lay-href="/user/login" class="layadmin-user-jump-change layadmin-link layui-hide-xs">{{ lang1['already have an account? sign in'] }}</a>
        <a lay-href="/user/login" class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">{{ lang1['sign in'] }}</a>
      </div>
    </div>
  </div>
  
  <div class="layui-trans layadmin-user-login-footer">
    
    <p>© All Rights Reserved</p>
  </div>

</div>
</script>

<script>
layui.use(['admin', 'form', 'user'], function(){
  var $ = layui.$
  ,setter = layui.setter
  ,admin = layui.admin
  ,form = layui.form
  ,je= layui.common
  ,router = layui.router();



  form.render();
  setTimeout(function (){
    $('#LAY-user-login-parentid').val(je._GET('invite'));
    form.render('checkbox');
  },100);

  //发送短信验证码
  admin.sendAuthCode({
    elem: '#LAY-user-reg-getsmscode'
    ,elemPhone: '#LAY-user-login-cellphone'
    ,elemVercode: '#LAY-user-login-vercode'
    ,ajax: {
      url: '../index/tools/sendEmailVerify' //实际使用请改成服务端真实接口
    }
  });

  //提交
  form.on('submit(LAY-user-reg-submit)', function(obj){
    let field = obj.field;
    console.log(field);
    //确认密码
    if(field.password !== field.repass){
      return layer.msg(lang1['the two password entries are inconsistent']);
    }

    //是否同意用户协议
    if(!field.agree){
      return layer.msg(lang1['you must agree to the user agreement to register']);
    }
    
    //请求接口
    admin.req({
      url: './index/reg' //实际使用请改成服务端真实接口
      ,type:'post'
      ,data: field
      ,done: function(res){
        if(res.code==0)
          layer.msg(lang1['successful registration'], {
            offset: '15px'
            ,icon: 1
            ,time: 1000
          }, function(){
            location.hash = '/user/login'; //跳转到登入页
          });
      }
    });
    
    return false;
  });
});
</script>